package com.alan.wifishare.view.impl.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alan.libapi.test.ITest;
import com.alan.libapi.test.TestTcpAPI;
import com.alan.wifishare.R;

/**
 * @className: MainMyFragment
 * @describtion: MainMyFragment
 * @author: AlanWang
 * @email: 850267876@qq.com
 * @time: 2016/4/20 18:38
 */
public class MainMyFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.main_my_layout, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        initView();
        iTest = new TestTcpAPI();
        iTest.start();
        super.onActivityCreated(savedInstanceState);
    }


    private TestTcpAPI iTest;
    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.sendMasterInfoTv:
                    iTest.sendMasterInfo();
                    break;
                case R.id.sendWifiInfoTv:
                    iTest.sendWifiInfo();
                    break;
                case R.id.modifyDeviceWifiTv:
                    iTest.modifyDeviceWifi();
                    break;
                case R.id.getDeviceUserListTv:
                    iTest.getDeviceUserList();
                    break;
                case R.id.deleteDeviceUserTv:
                    iTest.deleteDeviceUser();
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    public void onDestroy() {
        iTest.finish();
        super.onDestroy();
    }

    private TextView sendMasterInfoTv;
    private TextView sendWifiInfoTv;
    private TextView modifyDeviceWifiTv;
    private TextView getDeviceUserListTv;
    private TextView deleteDeviceUserTv;
    private void initView(){

        sendMasterInfoTv = (TextView) getView().findViewById(R.id.sendMasterInfoTv);
        sendWifiInfoTv = (TextView) getView().findViewById(R.id.sendWifiInfoTv);
        modifyDeviceWifiTv = (TextView) getView().findViewById(R.id.modifyDeviceWifiTv);
        getDeviceUserListTv = (TextView) getView().findViewById(R.id.getDeviceUserListTv);
        deleteDeviceUserTv = (TextView) getView().findViewById(R.id.deleteDeviceUserTv);

        sendMasterInfoTv.setOnClickListener(onClickListener);
        sendWifiInfoTv.setOnClickListener(onClickListener);
        modifyDeviceWifiTv.setOnClickListener(onClickListener);
        getDeviceUserListTv.setOnClickListener(onClickListener);
        deleteDeviceUserTv.setOnClickListener(onClickListener);
    }
}
